import { CopyControllerBase } from "./CopyControllerBase";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { CountryMoneyCopyInfoPanel } from "../../countryMoney/CountryMoneyCopyInfoPanel";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SCountryMoneyCopyInfo } from "../../../../../Message/Public/SCountryMoneyCopyInfo";
//class CountryMoneyCopyController
    
    export  class CountryMoneyCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCountryMoneyCopyInfo, this.copyInfoHandler);
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            if (this._infoPanel == null) 
            {
                this._infoPanel = new CountryMoneyCopyInfoPanel();
            }
            this._infoPanel.updatePosition();
            this._infoPanel.show();
            Dispatcher.dispatchEvent(new DataEvent(EventName.CountryMoneyWindowHide));
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            if (this._infoPanel != null) 
            {
                this._infoPanel.dispose();
                this._infoPanel = null;
            }
            return;
        }

        protected /* override */ addListener(): void
        {
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicCountryMoneyCopyInfo, this.copyInfoHandler);
            super.addListener();
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCountryMoneyCopyInfo, this.copyInfoHandler);
            return;
        }

        protected /* override */ removeListener(): void
        {
            super.removeListener();
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicCountryMoneyCopyInfo, this.copyInfoHandler);
            return;
        }

        /* internal  */copyInfoHandler(arg1: MessageBlock): void
        {
            if (this._infoPanel == null) 
            {
                return;
            }
            this._infoPanel.updateCopyInfo(arg1.messageBase as SCountryMoneyCopyInfo);
            return;
        }

        /* internal */ /* var */_infoPanel: CountryMoneyCopyInfoPanel;
    }
